package com.lei.springbootpractice.controller;

// src/main/java/com/lei/springbootpractice/controller/GlobalExceptionHandler.java

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.NoHandlerFoundException;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(NoHandlerFoundException.class)
    public ModelAndView handleNotFound(NoHandlerFoundException ex) {
        ModelAndView mav = new ModelAndView();
        mav.setViewName("error/404"); // 对应 templates/error/404.html
        mav.setStatus(HttpStatus.NOT_FOUND);
        return mav;
    }
}
